$(function () {
    //======================
    //======设置查询条件========
    //======================
    //内部公司
    $("#yhck_toolbar [name='yhckgsId']").gsjgtree(1);
    //起始时间
    $("#yhck_toolbar [name='yhckendDate']").datebox();
    //搜索按钮
    $("#yhck_toolbar [name='searchButton']").click(function () {
        $(grid).datagrid({
            queryParams: {
                date: $("#yhck_toolbar [name='yhckendDate']").val(),
                gsId: $("#yhck_toolbar [name='yhckgsId']").val(),
                zhlx: $("#yhck_toolbar [name='zhlx']").val()
            }});
    });


//======================
//========统计列表========
//======================
    var yhckcolumns = [
        [
            {field: 'gsmc', title: '公司名称', width: 100, align: 'center'},
            {field: 'khhzh', title: '开户行账户', width: 100, align: 'center'},
            {field: 'khhmc', title: '开户行名称', width: 100, align: 'center'},
            {field: 'zhlx', title: '账户类型',width: 100, align: 'center'},
            {field: "ckzh", title: "账户余额", width: 70, align: 'right', formatter: function (value, row, index) {
                if (row["gsmc"] == '合计') {
                    return '<span style="color:red;font-size:12pt">' + formatJe2(value, ",", ".") + '</span>';
                } else {
                    return '<a href="#" id = "yhck_zkzh_mx" class="ye-linkbutton" style="color:red" gsId="' + row["gsid"] + '"  zh="' + row["khhzh"] + '" >' + formatJe2(value, ",", ".") + '</a>';
                }
            }}
        ]
    ];

    var grid = $('#yhck_grid').datagrid({
        url: $.webPath() + '/report/yhck/yhckList',
        toolbar: "#yhck_toolbar",
        rownumbers: true,
        singleSelect: true,
        collapsible: true,
        fit: true,
        fitColumns: true,
        showFooter: true,
        queryParams: {
            date: $("#yhck_toolbar [name='yhckendDate']").val()
        },
//        $("#yhck_zkzh_mx")
        columns: yhckcolumns,
        onLoadSuccess: function () {
            var endDate =  $("#yhck_toolbar [name='yhckendDate']").val();
            $(".ye-linkbutton").linkbutton({plain: true}).unbind("click").bind("click", function () {
                $.window({
                    title: '银行存款明细',
                    width: 980,
                    height: 600,
                    cache: false,
                    maximizable: true,
                    url: $.webPath() + '/report/yhck/yhck_zkzh_mx?gsId=' + $(this).attr("gsId") + '&&zh=' + $(this).attr("zh")+ '&&endDate=' +endDate,
                    modal: true,
                    buttons: [],
                    onMaximize: function () {
                        $(this).find("#yhck_mx_grid").edatagrid("resize");
                    },
                    onRestore: function () {
                        $(this).find("#yhck_mx_grid").edatagrid("resize");
                    }
                });
            });
            $(".datagrid-htable .datagrid-cell").css('text-align', 'center');
        }
    });
});
